package service;

import model.Movie;
import util.LogUtil;

import java.util.*;

public class MovieService {
    private List<Movie> movies = new ArrayList<>();

    public void movieManageMenu(Scanner sc) {
        System.out.println("1. 列出所有影片 2. 添加影片 3. 删除影片 4. 修改影片 5. 返回");
        int op = sc.nextInt();
        switch (op) {
            case 1:
                for (Movie m : movies) {
                    System.out.println(m.getName() + " " + m.getDirector() + " " + m.getMainActor() + " " + m.getDescription() + " " + m.getDuration() + "分钟 " + m.getScore() + "分");
                }
                break;
            case 2:
                System.out.print("片名: ");
                String name = sc.next();
                System.out.print("导演: ");
                String director = sc.next();
                System.out.print("主演: ");
                String mainActor = sc.next();
                System.out.print("简介: ");
                String desc = sc.next();
                System.out.print("时长(分钟): ");
                int duration = sc.nextInt();
                System.out.print("评分(0-10): ");
                int score = sc.nextInt();
                movies.add(new Movie(name, director, mainActor, desc, duration, score));
                LogUtil.log("添加影片", name);
                System.out.println("添加成功！");
                break;
            case 3:
                System.out.print("输入要删除的片名: ");
                String delName = sc.next();
                movies.removeIf(m -> m.getName().equals(delName));
                LogUtil.log("删除影片", delName);
                System.out.println("删除成功！");
                break;
            case 4:
                System.out.print("输入要修改的片名: ");
                String mname = sc.next();
                for (Movie m : movies) {
                    if (m.getName().equals(mname)) {
                        System.out.print("新导演: ");
                        m.setDirector(sc.next());
                        System.out.print("新主演: ");
                        m.setMainActor(sc.next());
                        System.out.print("新简介: ");
                        m.setDescription(sc.next());
                        System.out.print("新时长: ");
                        m.setDuration(sc.nextInt());
                        System.out.print("新评分: ");
                        m.setScore(sc.nextInt());
                        LogUtil.log("修改影片", mname);
                        System.out.println("修改成功！");
                        return;
                    }
                }
                System.out.println("未找到影片！");
                break;
            case 5:
                return;
        }
    }

    public List<Movie> getMovies() {
        return movies;
    }
}